package com.qianfeng.pay.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.qianfeng.pay.R;
import com.qianfeng.pay.bean.ProductDetail;

import java.util.List;

/**
 * Created by Administrator on 8/12/2015.
 */
public class ProductListAdapter extends BaseAdapter{

    private List<ProductDetail> m_productList = null;
    private Context context;
    LayoutInflater inflater;
    public ProductListAdapter(Context context, List<ProductDetail> list) {
        this.context = context;
        this.m_productList = list;
        inflater = LayoutInflater.from(context);
    }


    private class ProductItemView {
        TextView subject;
        TextView body;
        TextView price;
    }

    public int getCount() {
        return m_productList.size();
    }

    public Object getItem(int position) {
        return m_productList.get(position);
    }

    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ProductItemView itemView;
        if (convertView == null) {
            itemView = new ProductItemView();
            convertView = LayoutInflater.from(context).inflate(
                    R.layout.product_item, null);
            itemView.subject = (TextView) convertView
                    .findViewById(R.id.subject);
            itemView.body = (TextView) convertView.findViewById(R.id.body);
            itemView.price = (TextView) convertView.findViewById(R.id.price);

            convertView.setTag(itemView);
        } else {
            itemView = (ProductItemView) convertView.getTag();
        }

        itemView.subject.setText(this.m_productList.get(position).subject);
        itemView.body.setText(this.m_productList.get(position).body);
        itemView.price.setText(this.m_productList.get(position).price);

        return convertView;
    }

}
